##################################################
#
# TABLES OF "LAGGED REPLICATIONS" FOR
# OIL, ISLAM, and WOMEN PROJECT
#
# Paul Musgrave and Yu-Ming Liou
# musgrave@umass.edu and yl254@georgetown.edu
#
# Created 27 February 2016
#
##################################################

##################################################
# R Housekeeping
##################################################

# Remove and empty workspace
rm(list=ls())

#  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  # 
# Load Packages
#  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  # 

library(foreign)
library(sandwich)
library(apsrtable)
library(stargazer)
library(tonymisc)  # includes summaryR()
library(MASS) # for polr() which runs our ologit

#  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  # 
# Load Functions
#  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  # 

# Change this to  your working directory
mywd <- "/Users/paulmusgrave/Dropbox/0001 Academic Projects/Ongoing/0127 Oil Islam Women/ISQ Accepted Submission/Replication"

setwd(paste(mywd,"/Code",sep=""))
 
source("statifyFN.R")
source("multipleOLSFN.R")
source("genModelsFN.R")
source("plotlineFN.R")
source("plotprepFN.R")
source("modelDefinitions.R")
source("tableOLSFN.R")
source("prepper.R")
source("helperFN.R")
tablenames <- read.csv("allmodels.csv", stringsAsFactors=FALSE)

p142.09.names <- prepper(p142.09)
#  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  # 
# Load Data
#  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  # 

setwd(paste(mywd,"/Data",sep=""))

data <- read.dta("NewDVModelsXSforISQFINAL2015.dta")
data$logGDPcap6372_sq <- data$logGDPcap6372 * data$logGDPcap6372

setwd(paste(mywd,"/Drafts/Tables",sep=""))


#################################################
#
# Models of Oil Income and Vice Issues
# 
#################################################

# Our FLFP Models
tab.harsh.yupaulalt <- tableOLS(formulas=genModels(c("laborfemaleMOD_2000"),
                                                 c(p140earlyalt)),
                              modelnames=c(names(p142early)))

stargazer(tab.harsh.yupaulalt,
          title= "Our Models from Lagged Replication Table",
          dep.var.labels = c("FLFP"),
          covariate.labels=c(p140earlyalt.names[,2],"Intercept"),
          out="ISQFINALAppendixTable10.tex",
          style="apsr",
          label="tab:harshout2",
          no.space=TRUE,
          omit.stat=c("ser","f"))


# Ross FLFP Models
tab.harsh.rossalt <- tableOLS(formulas=genModels(c("laborfemaleMOD_2000"),
                                             c(p140alt)),
                          modelnames=c(names(p140base)))

stargazer(tab.harsh.rossalt,
          title= "Ross Models from Lagged Replication Table",
          dep.var.labels = c("FLFP"),
          covariate.labels=c(p140alt.names[,2],"Intercept"),
          out="ISQFINALAppendixTable09.tex",
          style="apsr",
          label="tab:harshout1",
          no.space=TRUE,
          omit.stat=c("ser","f"))


# Ross Parliament
tab.harsh.rossparliament <- tableOLS(formulas=genModels(c("female_seats_2000"),
                                                 c(p142base)),
                              modelnames=c(names(p142base)))

stargazer(tab.harsh.rossparliament,
          title= "Ross Models from Lagged Replication Table",
          dep.var.labels = c("Women's Parliamentary Share"),
          covariate.labels=c(p142base.names[,2],"Intercept"),
          out="ISQFINALAppendixTable11.tex",
          style="apsr",
          label="tab:harshout1parli",
          no.space=TRUE,
          omit.stat=c("ser","f"))

# Our Parliament Models
tab.harsh.yupaul.parliament <- tableOLS(formulas=genModels(c("female_seats_2000"),
                                                        c(p142early)),
                                     modelnames=c(names(p142early)))

stargazer(tab.harsh.yupaul.parliament,
          title= "Our Models from Lagged Replication Table",
          dep.var.labels = c("Women's Parliamentary Share"),
          covariate.labels=c(p142early.names[,2],"Intercept"),
          out="ISQFINALAppendixTable12.tex",
          style="apsr",
          label="tab:harshout2parli",
          no.space=TRUE,
          omit.stat=c("ser","f"))